import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import { fileURLToPath, URL } from 'url'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue({
    template: {
      compilerOptions: {
        // 以此开头调过组件检测 使用自定义web components
        isCustomElement: (tag) => tag.includes('qingdai-')
      }
    }
  }),
  AutoImport({
    imports: ['vue'],
    dts: "src/auto-import.d.ts"
  }),
  ],
  server: {
    // host: '0.0.0.0',//自定义主机名
    port: 8081,//自定义端口
    proxy: {
      '/api': {
        target: 'http://localhost:8000/QingDai',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        //给所有vue组件内<style>添加引入
        additionalData: '@import "./src/style/bem.scss";'
      }
    },
    postcss: {
      // plugins: [PostCsspxToViewport()]
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    }
  }
})
